# Copyright 2018- The Pixie Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@io_bazel_rules_docker//container:container.bzl", "container_push")
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
    name = "pixie_cli_lib",
    srcs = ["px.go"],
    importpath = "px.dev/pixie/src/pixie_cli",
    visibility = ["//visibility:private"],
    deps = [
        "//src/pixie_cli/pkg/cmd",
        "//src/pixie_cli/pkg/pxanalytics",
        "//src/pixie_cli/pkg/pxconfig",
        "//src/pixie_cli/pkg/sentryhook",
        "//src/pixie_cli/pkg/utils",
        "//src/shared/goversion",
        "@com_github_getsentry_sentry_go//:sentry-go",
        "@com_github_sirupsen_logrus//:logrus",
        "@in_gopkg_segmentio_analytics_go_v3//:analytics-go_v3",
    ],
)

go_binary(
    name = "px",
    embed = [":pixie_cli_lib"],
    visibility = ["//src:__subpackages__"],
)

go_binary(
    name = "px_darwin_arm64",
    embed = [":pixie_cli_lib"],
    goarch = "arm64",
    goos = "darwin",
    visibility = ["//src:__subpackages__"],
)

go_binary(
    name = "px_darwin_amd64",
    embed = [":pixie_cli_lib"],
    goarch = "amd64",
    goos = "darwin",
    visibility = ["//src:__subpackages__"],
)

filegroup(
    name = "installer_script",
    srcs = ["install.sh"],
    visibility = ["//src:__subpackages__"],
)

go_image(
    name = "px_image",
    binary = ":px",
    importpath = "px.dev/pixie",
)

pkg_tar(
    name = "px_darwin_amd64_pkg",
    srcs = [
        ":px_darwin_amd64",
    ],
)

pkg_tar(
    name = "px_darwin_arm64_pkg",
    srcs = [
        ":px_darwin_arm64",
    ],
)

container_push(
    name = "push_px_image",
    format = "Docker",
    image = ":px_image",
    registry = "gcr.io",
    repository = "pixie-prod/pixie-prod-artifacts/px",
    tag = "{STABLE_BUILD_TAG}",
)

container_push(
    name = "push_px_image_to_docker",
    format = "Docker",
    image = ":px_image",
    registry = "index.docker.io",
    repository = "pixielabs/px",
    tag = "{STABLE_BUILD_TAG}",
)
